
const { NativeModules } = require("react-native");
function uuidv4(){
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
    var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8);
    return v.toString(16);
  });
}
class BaseService {

  async commonRequest(url) {

    ////console.log(222)
    const reqId = uuidv4()
    ////console.log('reqid:',reqId);
    //////console.log(opts)
    return new Promise((resolve, reject) => {
      NativeModules.ToolModule.sendKW(`${url}&reqId=${reqId}`).then((r) => {
        if(r.body) {
          ////console.log(r);
          try {
            resolve(JSON.parse(r.body))
          }catch (e) {
            reject(e)
          }

        }
        else
          resolve(r)
      })
    })


  }
}

module.exports = BaseService
